;; 设置垃圾回收，在Windows下，emacs25版本会频繁出发垃圾回收，所以需要设置
(when (eq system-type 'windows-nt)
  (setq gc-cons-threshold (* 512 1024 1024))
  (setq gc-cons-percentage 0.5)
  (run-with-idle-timer 5 t #'garbage-collect)
  ;; 显示垃圾回收信息，这个可以作为调试用
  ;; (setq garbage-collection-messages t)
  )

(global-subword-mode 1);;通过驼峰命名方式移动光标 camelCaseWords

;;popwin 弹出的窗口管理器
(require 'popwin)
(popwin-mode 1)
(global-set-key (kbd "C-z") popwin:keymap)

;;全局启用自动补全
(global-company-mode t)
;;hungry-delete
(global-hungry-delete-mode)
;;忽略提示音
(setq ring-bell-function 'ignore)
;;取消备份文件
(setq make-backup-files nil)
;;自动文件加载
(global-auto-revert-mode t)
;;覆盖选中内容
(delete-selection-mode 1)
;;全局启用行号
(global-linum-mode t)
;;设置默认encodeing
;;(set-language-environment "UTF-8")
;;;; 解决文件目录的中文名乱码
;;(setq-default pathname-coding-system 'utf-8)
;;(set-file-name-coding-system 'utf-8)

(put 'dired-find-alternate-file 'disabled nil);;文件夹目录使用同一个缓冲区
(setq dired-dwin-target 1);;文件分屏使用地址

;; 延迟加载 dired
(with-eval-after-load 'dired
  (define-key dired-mode-map (kbd "RET") 'dired-find-alternate-file))
(require 'dired-x)


;;开启区域括号高亮
(defadvice show-paren-function (around fix-show-paren-function activate)
  (cond ((looking-at-p "\\s(") ad-do-it)
	(t (save-excursion
	     (ignore-errors (backward-up-list))
	     ad-do-it)))
  )
(add-hook 'emacs-lisp-mode-hook 'show-paren-mode)


;;swiper
;;(ivy-mode 1)
;;(setq ivy-use-virtual-buffers t)
;;(setq enable-recursive-minibuffers t)
;;flycheck js错误检查
;;(global-flycheck-mode t)
;;(add-hook 'js2-mode-hook 'flycheck-mode) 

;;(require 'yasnippet)
;;(yas-reload-all)
;;(add-hook 'prog-mode-hook #'yas-minor-mode);;


;;js2-mode 配置
;;(setq auto-mode-alist
;;      (append
;;       '(
;;	 ("\\.js\\'" . js2-mode)
;;	 ("\\.html\\'" . web-mode)
;;	 )
;;       auto-mode-alist))

;;自定义自动补全
;;(setq-default abbrev-mode t)
;;(define-abbrev-table 'global-abbrev-table '(
;;					    ("6g" "gensir")
;;					    ))

;;hippie 补全设置
;;(setq hippie-expand-try-function-list '(try-expand-debbrev
;;					try-expand-debbrev-all-buffers
;;					try-expand-debbrev-from-kill
;;					try-complete-file-name-partially
;;					try-complete-file-name
;;					try-expand-all-abbrevs
;;					try-expand-list
;;					try-expand-line
;;					try-complete-lisp-symbol-partially
;;					try-complete-lisp-symbol))
;;简化yes or no
;;(fset 'yes-or-no-p 'y-or-n-p)
;;(setq dired-recursive-deletes 'always)
;;(setq dired-recursive-copies 'always)


;;web-mode 配置
;;(defun my-web-mode-indent-setup ()
;;  (setq web-mode-markup-indent-offset 2) ; web-mode, html tag in html file
;;  (setq web-mode-css-indent-offset 2)    ; web-mode, css in html file
;;  (setq web-mode-code-indent-offset 2)   ; web-mode, js code in html file
;;  )
;;(add-hook 'web-mode-hook 'my-web-mode-indent-setup)

;;窗口操作
;;编辑操作
;;代码提示
;;代码片段


(provide 'init-better-defaults)
